package com.ericsson.resourceplanner.utils;

import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityContextRolesUtils {

	public String[] getRoles(SecurityContext sc)
	{
		
		/*System.out.println("UserName = "+sc.getAuthentication().getName());
		System.out.println("User Roles = "+sc.getAuthentication().getAuthorities());*/
		
		String [] role = sc.getAuthentication().getAuthorities().toString().split(",");
		role[0] = role[0].substring(1);
		//role[role.length - 1] = role[role.length - 1].substring(0,  role[role.length - 1].length()-1);
		int length = role.length -1;
		int indx = role[length].indexOf(']');
	
				
		role[length] = role[length].substring(1,indx);
	    
		for(int i = 0 ; i <= length ; i++)
	    {
			role[i] = role[i].trim();
	    	//System.out.println("----------------------------------"+role[i]);
	    }
		
		return role;
	}
}
